import { Controller, Get, Post, UseGuards, Req, Request } from '@nestjs/common';
import { AuthGuard } from '@nestjs/passport';
// import { Request } from 'express';
import { AppService } from './app.service';
import { AuthService } from './auth/auth.service';
import { Roles } from './roles.decorator';
import { Role } from './auth/role.enum';

@Controller()
export class AppController {
  constructor(
    // private readonly appService: AppService,
    private readonly authService: AuthService,
  ) {}

  @Get()
  getHello(): string {
    // return this.appService.getHello();
    return '';
  }

  @UseGuards(AuthGuard('local'))
  @Post('auth/login1')
  async login(@Request() req) {
    // console.log(req);
    // console.log(req.user + 'zz');
    // return req.user;
    return this.authService.login(req);
  }

  @UseGuards(AuthGuard('jwt'))
  @Get('profile')
  getProfile(@Request() req) {
    return req.user;
  }

  @Post('test1')
  test(@Req() req) {
    // console.log(req.body);
    return req.user;
  }

  @Post('test2')
  @Roles(Role.Admin)
  test2(@Req() req) {
    return req.user;
  }
}
